﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;

using PowerCreator.LMS.CMS.Entity;
using PowerCreator.LMS.Web.NetMeeting;
using PowerCreator.LMS.NetMeeting.Entity;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_NetMeetingManager_AddMeeting : PowerCreator.LMS.Web.Base.BasePage
{
    ManagerNetMeeting objManagerNetMeeting = new ManagerNetMeeting();
    LogicServer.NetMeetingClass objNetMeetingClass = new LogicServer.NetMeetingClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //{
        //    Script.RedirectURL(GetRefUrl());
        //}
        if (!IsPostBack)
        {
            InitPage();
           
            int NewID = 0;
            if (Request.QueryString["MeetingID"] != null)
            {
                NewID = int.Parse(Request.QueryString["MeetingID"].ToString());
                ViewState["MeetingID"] = NewID.ToString();
                BinderForm(NewID);
            }
      

        }
    }
    protected override  void InitPage()
    {
        //lbl_InfoTitle.Text = GetLanageValueByKey("lbl_AddJob_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobName.Text = GetLanageValueByKey("lbl_AddJob_JobName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobDescription.Text = GetLanageValueByKey("lbl_AddJob_JobDescription", PowerCreator.LMS.Language.LanagetItemType.Page);

        //btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        //btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        //base.InitPage();

        //lbl_InfoTitle_AddNew.Text = GetLanageValueByKey("lab_AddNew_AddNews", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_NewBaseInfo.Text = GetLanageValueByKey("lab_AddNew_NewsSet", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_NewAttributeInfo.Text = GetLanageValueByKey("lab_AddNew_OtherNewsSet", PowerCreator.LMS.Language.LanagetItemType.Page);
        ////lbl_NewUploadInfo.Text = "新闻相关文件上传";
        //lbl_MeetName.Text = GetLanageValueByKey("lab_AddNew_NewsTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lab_MeetingPassword.Text = GetLanageValueByKey("lab_AddNew_NewsShortTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_MeetingDescription.Text = GetLanageValueByKey("lab_AddNew_NewsContent", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_MaxConnects.Text = GetLanageValueByKey("lab_AddNew_NewsType", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_MeetingType.Text = GetLanageValueByKey("lab_AddNew_Guanjianci", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_MeetingAffiche.Text = GetLanageValueByKey("lbl_AddResourceInfo_AuthorName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_MeetingImageIndex.Text = GetLanageValueByKey("lab_AddNew_NewsSourse", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_NewIsTop.Text = GetLanageValueByKey("lab_AddNew_IsTop", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_NewTrainClaID.Text = GetLanageValueByKey("lbl_ADDNew_TrainClaID", PowerCreator.LMS.Language.LanagetItemType.Page);
        //cb_NewIsTop.Text = "";
        //lbl_NewFileUrl.Text = "附件";
        //lbl_NewPictureUrl.Text = "图片";
        //lbl_NewPictureUrl_intro.Text = "只有在前台页面做特殊展示，例如做图片新闻时才需上传！";

        btnSave.Text = "保存"; //GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = "返回";// GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }


   
    private void BinderForm(int id)
    {
    
        TMeeting vo = new TMeeting();
        vo = objManagerNetMeeting.LoadTMeeting(id);
        txt_MeetName.Text = vo.MeetingName;
        txt_PassWord.Text = vo.MeetingPassword;
        txt_Description.Text = vo.MeetingDescription;
        txt_MaxConnects.Text = vo.MaxConnects.ToString();

        
       
        txt_MeetingType.Text = vo.MeetingType.ToString();
        txt_MeetingAffiche.Text = vo.MeetingAffiche;
        txt_MeetingImageIndex.Text = vo.MeetingImageIndex.ToString();
       
    }
    private bool CheckPageData()
    {


        if (!PowerCreator.LMS.Common.Utils.PageValidate.IsNumber(txt_MaxConnects.Text.Trim()))
        {

            lbl_msg_Error.Text = "MaxConnects请输入整数";
            return false;
        }
        if (!PowerCreator.LMS.Common.Utils.PageValidate.IsNumber(txt_MeetingType.Text.Trim()))
        {

            lbl_msg_Error.Text = "txt_MeetingType请输入整数";
            return false;
        }
        if (!PowerCreator.LMS.Common.Utils.PageValidate.IsNumber(txt_MeetingImageIndex.Text.Trim()))
        {

            lbl_msg_Error.Text = "txt_MeetingImageIndex请输入整数";
            return false;
        }
        //string search = string.Format("MeetingName = '{0}'", txt_MeetName.Text.Trim());
        //if (ViewState["MeetingID"] != null)
        //{
        //    search += "and MeetingID<>" + ViewState["MeetingID"].ToString();
        //}
        //if (objManagerNetMeeting.CountTMeeting(search) != 0)
        //{

        //    //lbl_msg_Error.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_count", PowerCreator.LMS.Language.LanagetItemType.MSG);

        //    lbl_msg_Error.Text = "<br />" + GetLanageValueByKey("msg_AddNew_msg", PowerCreator.LMS.Language.LanagetItemType.Page);
        //    return false;
        //}

        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        TMeeting vo = new TMeeting();
        if (ViewState["MeetingID"] != null)
        {
            vo = objManagerNetMeeting.LoadTMeeting(int.Parse(ViewState["MeetingID"].ToString()));
        }
        vo.MeetingName = txt_MeetName.Text.Trim();
        vo.MeetingPassword = txt_PassWord.Text.Trim();

        vo.MeetingDescription = txt_Description.Text;
        vo.MaxConnects=int.Parse(txt_MaxConnects.Text.Trim());
        
        vo.MeetingType = int.Parse(txt_MeetingType.Text.Trim());
        vo.MeetingAffiche = txt_MeetingAffiche.Text.Trim();
        vo.MeetingImageIndex = int.Parse(txt_MeetingImageIndex.Text.Trim());



        if (ViewState["MeetingID"] == null)
        {
            int MeetingID=objManagerNetMeeting.AddNewTMeeting_ReturnID(vo);
            if (MeetingID>0)
            {
                objNetMeetingClass.WebAddMeeting(MeetingID, vo.MeetingName, vo.MeetingPassword, vo.MaxConnects, vo.MeetingType, vo.MeetingImageIndex, vo.MeetingAffiche, vo.MeetingDescription);
                string url = "ManagerMeeting.aspx";
                Script.RedirectURL(url);
            }
        }
        else
        {
            if (objManagerNetMeeting.UpdateTMeeting(vo))
            {
                objNetMeetingClass.WebModifyMeeting(vo.MeetingID, vo.MeetingName, vo.MeetingPassword, vo.MaxConnects, vo.MeetingType, vo.MeetingImageIndex, vo.MeetingAffiche, vo.MeetingDescription);
                string url = "ManagerMeeting.aspx";
                Script.RedirectURL(url);
            }
        }
    }

   
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "ManagerNew.aspx";
        Script.RedirectURL(url);
    }
}
